# -*- coding: utf-8 -*-
# File : multi_thread.py
# Author: taoyahui
# Date : 2022/6/1

import threading
import requests
import re
import datetime

pattern = re.compile("<a href='problem.php\?id=\d+'>(.*?)</a>")

class MyThread(threading.Thread):
    def __init__(self, page):
        threading.Thread.__init__(self)
        self.page = page

    def run(self):
        response = requests.get('http://10.10.74.125/problemset.php?page=%s' % (self.page))
        html = response.text
        result = pattern.findall(html)
        with open('result2.txt', 'w') as f:
            for i in result:
                f.write(i + '\n')

def main():
    for i in range(8):
        t = MyThread(i + 1)
        t.start()
        t.join()

if __name__ == '__main__':
    startTime = datetime.datetime.now()
    for i in range(100):
        main()
    endTime = datetime.datetime.now()
    print("运行时间：%s毫秒" % ((endTime - startTime).total_seconds() * 1000))